package com.bootx.controller.api;

import org.apache.commons.io.FilenameUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.IOException;
import java.util.UUID;

/**
 * @author black
 */
@RestController
@RequestMapping("/api/file")
public class FileControllerController {
    @PostMapping("/upload")
    public String upload(MultipartFile file) throws IOException {
        String replace = UUID.randomUUID().toString().replace("-", "");
        file.getContentType();
        String extension = FilenameUtils.getExtension(file.getOriginalFilename());
        System.out.println(extension);
        String path = replace + "." + extension;
        File file1 = new File("d:/", path);
        file.transferTo(file1);
        return path;
    }

}
